package com.kingdee.eas.hr.affair.app;

import java.util.List;

import org.apache.log4j.Logger;

import com.kingdee.bos.BOSException;
import com.kingdee.bos.Context;
import com.kingdee.bos.dao.ormapping.ObjectUuidPK;
import com.kingdee.bos.util.BOSUuid;
import com.kingdee.eas.basedata.person.PersonInfo;
import com.kingdee.eas.common.EASBizException;
import com.kingdee.eas.custom.hr.base.AttendanceCodeFactory;
import com.kingdee.eas.custom.hr.base.AttendanceCodeInfo;
import com.kingdee.eas.custom.hr.base.DirectAndIndirectFactory;
import com.kingdee.eas.custom.hr.base.DirectAndIndirectInfo;
import com.kingdee.eas.hr.base.batch.BatchProcessedResult;
import com.kingdee.eas.hr.canon.cbase.AdminOrgBaseFactory;
import com.kingdee.eas.hr.canon.cbase.AdminOrgBaseInfo;
import com.kingdee.eas.hr.canon.cbase.GradeFactory;
import com.kingdee.eas.hr.canon.cbase.GradeInfo;

public class AffairBatchProcessFacadeControllerBeanEx extends
		com.kingdee.eas.hr.affair.app.AffairBatchProcessFacadeControllerBean {
	private static Logger logger = Logger
			.getLogger("com.kingdee.eas.hr.affair.app.AffairBatchProcessFacadeControllerBeanEx");

	@Override
	protected BatchProcessedResult _processPerson(Context ctx, List personInfos, String billID) throws BOSException,
			EASBizException {
		BatchProcessedResult result = super._processPerson(ctx, personInfos, billID);

		PersonInfo person = null;
		for (int i = 0; i < result.getResult().size(); i++) {
			person = (PersonInfo) result.getResult().get(i);
			if (person.getGrade() != null) {
				person.setGrade(this.getGradeInfo(ctx, person.getGrade().getId()));
			}

			if (person.getAdminOrgBase() != null) {
				person.setAdminOrgBase(this.getAdminOrgBaseInfo(ctx, person.getAdminOrgBase().getId()));
			}

			if (person.getAttendanceCode() != null) {
				person.setAttendanceCode(this.getAttendanceCodeInfo(ctx, person.getAttendanceCode().getId()));
			}

			if (person.getDirectAndIndirectDiff() != null) {
				person.setDirectAndIndirectDiff(this.getDirectAndIndirectInfo(ctx, person.getDirectAndIndirectDiff()
						.getId()));
			}
		}
		return result;
	}

	private GradeInfo getGradeInfo(Context ctx, BOSUuid id) throws BOSException, EASBizException {
		return GradeFactory.getLocalInstance(ctx).getGradeInfo(new ObjectUuidPK(id));
	}

	private AdminOrgBaseInfo getAdminOrgBaseInfo(Context ctx, BOSUuid id) throws BOSException, EASBizException {
		return AdminOrgBaseFactory.getLocalInstance(ctx).getAdminOrgBaseInfo(new ObjectUuidPK(id));
	}

	private DirectAndIndirectInfo getDirectAndIndirectInfo(Context ctx, BOSUuid id) throws BOSException,
			EASBizException {
		return DirectAndIndirectFactory.getLocalInstance(ctx).getDirectAndIndirectInfo(new ObjectUuidPK(id));
	}

	private AttendanceCodeInfo getAttendanceCodeInfo(Context ctx, BOSUuid id) throws BOSException, EASBizException {
		return AttendanceCodeFactory.getLocalInstance(ctx).getAttendanceCodeInfo(new ObjectUuidPK(id));
	}
}
